import {
  getHeader,
  isLoading,
  uploadFile
} from "./util";

export default {
  data() {
    return {
      baseURL: this.$baseURL,
    }
  },
  methods: {
    /**
     * 事件， form 的 key
     */
    deletePhoto(event, formName = 'form') {
      this[formName][event.name].splice(event.index, 1);
    },
    /**
     * 事件  form 的 key  类型
     */
    afterReadFive(info, formName = 'form', type) {
      const {
        file,
        name,
      } = info;
      let promiseList = file.map((v) => {
        return uploadFile({
          url: "/web/sys/upload/upload_file",
          filePath: v.url,
          name: "file",
          formData: {
            type,
          },
        });
      });
      isLoading();
      Promise.all(promiseList)
        .then((res) => {
          res.forEach((item) => {
            let result = item.result;
            this[formName][name].push({
              url: result.fullPath,
              halfPath: result.halfPath,
            });
          });
        })
        .catch((err) => {})
        .finally(() => {
          isLoading(false);
        });
    },
    // 获取上传 图片的 url 集合
    /**
     * 表单 form 
     * 提交给后端的字段
     */
    getUploadFileUrl(fileList) {
      return fileList.map(item => item.url)
    }
  }
}